# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
   
    # ======================================================
    # GLOBALLY USED FUNCTIONS
    # ======================================================
    def show_page_title
      return 'Desert Point Lodges, Where good people go!'
    end
  
    def nl2br(s)
       s.gsub(/\n/, '<br/>')
    end
  
    def URLDecode(str)
     str.gsub!(/%[a-fA-F0-9]{2}/) { |x| x = x[1..2].hex.chr }
    end

    def URLEncode(str)
       str.gsub!(/[^\w$&\-+.,\/:;=?@]/) { |x| x = format("%%%x", x[0]) }
    end 
  
    def str_chop(s, length)
      return s[0,length];
    end
  
    def rel_date(date)
      date = Date.parse(date, true) #unless /Date.*/ =~ date.class.to_s
      days = (date - Date.today).to_i

      return 'today'     if days >= 0 and days < 1
      return 'tomorrow'  if days >= 1 and days < 2
      return 'yesterday' if days >= -1 and days < 0

      return "in #{days} days"      if days.abs < 60 and days > 0
      return "#{days.abs} days ago" if days.abs < 60 and days < 0

      return date.strftime('%A, %B %e') if days.abs < 182
      return date.strftime('%A, %B %e, %Y')
    end
  
    # ======================================================
    # STREAMLINED SCAFFOLDING, TOP MENU
    # ======================================================
    def streamlined_top_menus
      [
        ["Welcomemessages", {:controller => "admin_welcomemessages"}],
        ["Reactions", {:controller => "admin_reactions"}],
        ["Users", {:controller => "admin_users"}],
        ["Comments", {:controller => "admin_comments"}],
        ["Bookings", {:controller => "admin_bookings"}]
      ]
    end
  
    # ======================================================
    # STREAMLINED SCAFFOLDING, SIDE MENU
    # ======================================================
    def streamlined_side_menus
      [
        ["New Welcomemess.", {:controller => "admin_welcomemessages", :action => "new"}],
        ["New Reaction", {:controller => "admin_reactions", :action => "new"}],
        ["New User", {:controller => "admin_users", :action => "new"}],
        ["New Comment", {:controller => "admin_comments", :action => "new"}],
        ["New Booking", {:controller => "admin_bookings", :action => "new"}]
      ]
    end
  
end
